package com.distribute.framework.config;

import org.apache.catalina.connector.Connector;
import org.springframework.boot.context.embedded.EmbeddedServletContainerFactory;
import org.springframework.boot.context.embedded.tomcat.TomcatEmbeddedServletContainerFactory;
import org.springframework.boot.context.properties.ConfigurationProperties;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

@Configuration
@ConfigurationProperties(prefix = "server.ajp")
public class TomcatAjpConfiguration {
	
	private int port = 7001;
	private boolean allowTrace = false;
	private boolean secure = false;
	private String scheme = "http";
	private boolean enabled = false;

	@Bean
	public EmbeddedServletContainerFactory servletContainer() {

		TomcatEmbeddedServletContainerFactory tomcat = new TomcatEmbeddedServletContainerFactory();
		if (isEnabled()) {
			System.out.println("ajp端口:"+getPort());
			Connector ajpConnector = new Connector("AJP/1.3");
			ajpConnector.setProtocol("AJP/1.3");
			ajpConnector.setPort(getPort());
			ajpConnector.setSecure(isSecure());
			ajpConnector.setAllowTrace(isAllowTrace());
			ajpConnector.setScheme(getScheme());
			tomcat.addAdditionalTomcatConnectors(ajpConnector);
		}

		return tomcat;
	}

	public int getPort() {
		return port;
	}

	public void setPort(int port) {
		this.port = port;
	}

	public boolean isAllowTrace() {
		return allowTrace;
	}

	public void setAllowTrace(boolean allowTrace) {
		this.allowTrace = allowTrace;
	}

	public boolean isSecure() {
		return secure;
	}

	public void setSecure(boolean secure) {
		this.secure = secure;
	}

	public String getScheme() {
		return scheme;
	}

	public void setScheme(String scheme) {
		this.scheme = scheme;
	}

	public boolean isEnabled() {
		return enabled;
	}

	public void setEnabled(boolean enabled) {
		this.enabled = enabled;
	}



}